﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="List.aspx.cs" Inherits="SysAdmin_Role_List" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <script type="text/javascript">
        var iconData = [{
            value: '',
            text: '默认'
        }, {
            value: 'icon-add',
            text: 'icon-add'
        }, {
            value: 'icon-edit',
            text: 'icon-edit'
        }, {
            value: 'icon-remove',
            text: 'icon-remove'
        }, {
            value: 'icon-save',
            text: 'icon-save'
        }, {
            value: 'icon-cut',
            text: 'icon-cut'
        }, {
            value: 'icon-ok',
            text: 'icon-ok'
        }, {
            value: 'icon-no',
            text: 'icon-no'
        }, {
            value: 'icon-cancel',
            text: 'icon-cancel'
        }, {
            value: 'icon-reload',
            text: 'icon-reload'
        }, {
            value: 'icon-search',
            text: 'icon-search'
        }, {
            value: 'icon-print',
            text: 'icon-print'
        }, {
            value: 'icon-help',
            text: 'icon-help'
        }, {
            value: 'icon-undo',
            text: 'icon-undo'
        }, {
            value: 'icon-redo',
            text: 'icon-redo'
        }, {
            value: 'icon-back',
            text: 'icon-back'
        }, {
            value: 'icon-sum',
            text: 'icon-sum'
        }, {
            value: 'icon-tip',
            text: 'icon-tip'
        }];
        $(function () {
            $('#role_datagrid').datagrid({
                url: 'Role/List.aspx?paramType=QueryList',
                fit: true,
                fitColumns: true,
                border: false,
                pagination: true,
                idField: 'roleCode',
                pageSize: 30,
                pageList: [10, 20, 30, 40, 50],
                sortName: 'text',
                sortOrder: 'asc',
                checkOnSelect: false,
                selectOnCheck: false,
                nowrap: false,
                frozenColumns: [[{
                    title: '编号',
                    field: 'id',
                    width: 150,
                    sortable: true,
                    checkbox: true
                }, {
                    title: '角色名称',
                    field: 'roleName',
                    width: 150,
                    sortable: true
                }]],
                columns: [[{
                    title: '可访问资源ID',
                    field: 'powerCodes',
                    width: 300,
                    hidden: true
                }, {
                    title: '可访问资源',
                    field: 'powerNames',
                    width: 300,
                    formatter: function (value, row, index) {
                        if (row.id == '0') {
                            return '可访问系统所有资源';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'action',
                    title: '动作',
                    width: 100,
                    formatter: function (value, row, index) {
                        if (row.id == '0') {
                            return '系统角色';
                        } else {
                            return formatString('<img onclick="sysadmin_role_edit(\'{0}\');" src="{1}"/>&nbsp;<img onclick="sysadmin_role_del(\'{2}\');" src="{3}"/>', row.roleCode, 'Images/pencil.png', row.roleCode, 'Images/cancel.png');
                        }
                    }
                }]],
                toolbar: [{
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {
                        sysadmin_role_add();
                    }
                }, '-'
                //, {
                //    text: '批量删除',
                //    iconCls: 'icon-remove',
                //    handler: function () {
                //        sysadmin_role_remove();
                //    }
                //}, '-'
                ]
            });
        });

        //添加角色
        function sysadmin_role_add() {

            $('#role_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');

            $('<div/>').dialog({
                href: 'Role/Add.aspx',
                width: 500,
                height: 200,
                modal: true,
                title: '添加角色',
                buttons: [{
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {

                        var d = $(this).closest('.window-body');
                        $('#admin_role_addForm').form('submit', {
                            url: 'Role/List.aspx?paramType=AddModel',
                            success: function (result) {
                                try {
                                    var r = $.parseJSON(result);
                                    if (r.success) {
                                        //$('#role_datagrid').datagrid('insertRow', {
                                        //    index: 0,
                                        //    row: r.obj
                                        //});
                                        $('#role_datagrid').datagrid('load', {});
                                        d.dialog('destroy');
                                    }
                                    $.messager.show({
                                        title: '提示',
                                        msg: r.msg
                                    });
                                } catch (e) {
                                    $.messager.alert('提示', result);
                                }
                            }
                        });
                    }
                }],
                onClose: function () {
                    $(this).dialog('destroy');
                }
            });
        }

        //编辑角色
        function sysadmin_role_edit(role_key) {
            $('<div/>').dialog({
                href: 'Role/Edit.aspx?role_key=' + role_key,
                width: 500,
                height: 200,
                modal: true,
                title: '角色编辑',
                buttons: [{
                    text: '编辑',
                    iconCls: 'icon-add',
                    handler: function () {
                        var d = $(this).closest('.window-body');
                        $('#admin_role_editForm').form('submit', {
                            url: 'Role/List.aspx?paramType=UpdateModel',
                            success: function (result) {
                                try {
                                    var r = $.parseJSON(result);
                                    if (r.success) {
                                        d.dialog('destroy');

                                        $('#role_datagrid').datagrid('reload');
                                    }
                                } catch (e) {

                                    $.messager.alert('提示', "增加失败，请重试！");
                                }
                            }
                        });
                    }
                }],
                onClose: function () {
                    $(this).dialog('destroy');
                }
            });
        }

        //删除菜单
        function sysadmin_role_del(role_key) {

            $.messager.confirm('提示', '你确定要删除该行数据么?', function (r) {
                if (r) {
                    $.ajax({
                        type: "POST",
                        url: 'Role/List.aspx',
                        data: "paramType=DelModel&roleCode=" + role_key,
                        dataType: "json",
                        success: function (msg) {
                            if (msg.success) {
                                $('#role_datagrid').datagrid('reload');
                            }
                        },
                        error: function (e, ex) {
                            $.messager.alert('错误提示', '删除失败！');
                        }

                    });
                }
            });
        }

    </script>
    <table id="role_datagrid"></table>
</body>
</html>
